package com.codeduck.storage.dubbo;

import com.codeduck.common.dubbo.IStorageDubboService;
import com.codeduck.common.response.ServiceResponse;
import com.codeduck.common.response.StorageResponse;
import com.codeduck.storage.domain.StorageDO;
import com.codeduck.storage.service.IStorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-08-20
 */
@Service
@Slf4j
public class StorageDubboService implements IStorageDubboService {

    @Resource
    private IStorageService storageService;

    @Override
    public ServiceResponse<StorageResponse> decreaseStorage(String commodityCode, Integer count) {
        log.info("库存扣减请求 = [商品编码：{}，商品扣除数量：{}]", commodityCode, count);
        StorageDO storageDO = storageService.decreaseStorage(commodityCode, count);
        StorageResponse storageResponse = StorageResponse
                .builder()
                .name(storageDO.getName())
                .commodityCode(storageDO.getCommodityCode())
                .count(storageDO.getCount())
                .build();
        return ServiceResponse.asOk(storageResponse);
    }
}
